import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/layout/Layout.vue';

const routesConfig = [
  {
    path: '/dangerous_rule_manage',
    name: 'dangerous',
    component: () => import('../views/dangerous/index.vue'),
  },
  {
    path: '/script_library',
    name: 'script_library',
    component: () => import('../views/scriptLibrary/index.vue'),
  },
  {
    path: '/workflow',
    name: 'workflow',
    component: () => import('@/views/workflow/index.vue'),
  },
  {
    path: '/workflow/addWorkflow',
    name: 'workflowAdd',
    meta: {
      title: '添加编排',
      hidden: true,
    },
    component: () => import('@/views/workflow/addWorkflow.vue'),
  },
  {
    path: '/jobs',
    name: 'jobs',
    component: () => import('../views/jobs/index.vue'),
  },
];
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: routesConfig,
    redirect: '/dangerous_rule_manage', // 将重定向逻辑合并
  },
  {
    path: '/plugin-automation',
    redirect: '/dangerous_rule_manage',
  },
];
const router = createRouter({
  history: createWebHistory(window.__MICRO_APP_BASE_ROUTE__ || process.env.BASE_URL),
  // 确保在微应用环境下也能正确匹配路由
  routes: window.__MICRO_APP_ENVIRONMENT__ ? [...routesConfig] : [...routes],
});

export default router;
